home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_375 / parm / command.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  232 lines

  1. /*
  2.  *    Command.c - Copyright © 1990 by S.R. & P.C.
  3.  *
  4.  *    Created:    01 Jul 1990
  5.  *    Modified:    07 Jul 1990
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. /*
  11. #define DO_ARP_COPIES
  12. #include <intuition/intuition.h>
  13. #include <libraries/arpbase.h>
  14. #include <functions.h>
  15. */
  16.  
  17. #include <dos_functions.h>
  18. #include <arpdos_pragmas.h>
  19.  
  20. #define OK        1
  21. #define CANCEL    2
  22. #define STRING    3
  23.  
  24. /*****                global functions                    *****/
  25.  
  26. void Command( void );
  27.  
  28. /*****                 local variables                    *****/
  29.  
  30. static UBYTE Buffer[128];
  31.  
  32. static struct StringInfo Gadget3SInfo = {
  33.     Buffer,    /* buffer where text will be edited */
  34.     NULL,    /* optional undo buffer */
  35.     0,    /* character position in buffer */
  36.     128,    /* maximum number of characters to allow */
  37.     0,    /* first displayed character buffer position */
  38.     0,0,0,0,0,    /* Intuition initialized and maintained variables */
  39.     0,    /* Rastport of gadget */
  40.     0,    /* initial value for integer gadgets */
  41.     NULL    /* alternate keymap (fill in if you set the flag) */
  42. };
  43.  
  44. static SHORT BorderVectors1[] = {
  45.     0,0,
  46.     293,0,
  47.     293,11,
  48.     0,11,
  49.     0,0
  50. };
  51.  
  52. static struct Border Border1 = {
  53.     -3,-2,    /* XY origin relative to container TopLeft */
  54.     2,0,JAM1,    /* front pen, back pen and drawmode */
  55.     5,    /* number of XY vectors */
  56.     BorderVectors1,    /* pointer to XY vectors */
  57.     NULL    /* next border in list */
  58. };
  59.  
  60. static struct Gadget Gadget3 = {
  61.     NULL,    /* next gadget */
  62.     12,17,    /* origin XY of hit box relative to window TopLeft */
  63.     288,10,    /* hit box width and height */
  64.     NULL,    /* gadget flags */
  65.     RELVERIFY,    /* activation flags */
  66.     STRGADGET,    /* gadget type flags */
  67.     (APTR)&Border1,    /* gadget border or image to be rendered */
  68.     NULL,    /* alternate imagery for selection */
  69.     NULL,    /* first IntuiText structure */
  70.     NULL,    /* gadget mutual-exclude long word */
  71.     (APTR)&Gadget3SInfo,    /* SpecialInfo structure */
  72.     STRING,    /* user-definable data */
  73.     NULL    /* pointer to user-definable data */
  74. };
  75.  
  76. static SHORT BorderVectors2[] = {
  77.     0,0,
  78.     72,0,
  79.     72,13,
  80.     0,13,
  81.     0,0
  82. };
  83.  
  84. static struct Border Border2 = {
  85.     -1,-1,    /* XY origin relative to container TopLeft */
  86.     2,0,JAM1,    /* front pen, back pen and drawmode */
  87.     5,    /* number of XY vectors */
  88.     BorderVectors2,    /* pointer to XY vectors */
  89.     NULL    /* next border in list */
  90. };
  91.  
  92. static struct IntuiText IText1 = {
  93.     1,0,JAM1,    /* front and back text pens, drawmode and fill byte */
  94.     12,2,    /* XY origin relative to container TopLeft */
  95.     NULL,    /* font pointer or NULL for default */
  96.     (UBYTE *)"Cancel",    /* pointer to text */
  97.     NULL    /* next IntuiText structure */
  98. };
  99.  
  100. static struct Gadget Gadget2 = {
  101.     &Gadget3,    /* next gadget */
  102.     229,36,    /* origin XY of hit box relative to window TopLeft */
  103.     71,12,    /* hit box width and height */
  104.     NULL,    /* gadget flags */
  105.     RELVERIFY+ENDGADGET,    /* activation flags */
  106.     BOOLGADGET,    /* gadget type flags */
  107.     (APTR)&Border2,    /* gadget border or image to be rendered */
  108.     NULL,    /* alternate imagery for selection */
  109.     &IText1,    /* first IntuiText structure */
  110.     NULL,    /* gadget mutual-exclude long word */
  111.     NULL,    /* SpecialInfo structure */
  112.     CANCEL,    /* user-definable data */
  113.     NULL    /* pointer to user-definable data */
  114. };
  115.  
  116. static SHORT BorderVectors3[] = {
  117.     0,0,
  118.     55,0,
  119.     55,13,
  120.     0,13,
  121.     0,0
  122. };
  123. static struct Border Border3 = {
  124.     -1,-1,    /* XY origin relative to container TopLeft */
  125.     2,0,JAM1,    /* front pen, back pen and drawmode */
  126.     5,    /* number of XY vectors */
  127.     BorderVectors3,    /* pointer to XY vectors */
  128.     NULL    /* next border in list */
  129. };
  130.  
  131. static struct IntuiText IText2 = {
  132.     1,0,JAM1,    /* front and back text pens, drawmode and fill byte */
  133.     17,2,    /* XY origin relative to container TopLeft */
  134.     NULL,    /* font pointer or NULL for default */
  135.     (UBYTE *)"Ok!",    /* pointer to text */
  136.     NULL    /* next IntuiText structure */
  137. };
  138.  
  139. static struct Gadget Gadget1 = {
  140.     &Gadget2,    /* next gadget */
  141.     12,36,    /* origin XY of hit box relative to window TopLeft */
  142.     54,12,    /* hit box width and height */
  143.     NULL,    /* gadget flags */
  144.     RELVERIFY+ENDGADGET,    /* activation flags */
  145.     BOOLGADGET,    /* gadget type flags */
  146.     (APTR)&Border3,    /* gadget border or image to be rendered */
  147.     NULL,    /* alternate imagery for selection */
  148.     &IText2,    /* first IntuiText structure */
  149.     NULL,    /* gadget mutual-exclude long word */
  150.     NULL,    /* SpecialInfo structure */
  151.     OK,    /* user-definable data */
  152.     NULL    /* pointer to user-definable data */
  153. };
  154.  
  155. static struct NewWindow ReqNewWin = {
  156.     0,11,    /* window XY origin relative to TopLeft of screen */
  157.     312,54,    /* window width and height */
  158.     0,1,    /* detail and block pens */
  159.     GADGETUP+ACTIVEWINDOW,    /* IDCMP flags */
  160.     WINDOWDRAG+WINDOWDEPTH+ACTIVATE+NOCAREREFRESH,    /* other window flags */
  161.     &Gadget1,    /* first gadget in gadget list */
  162.     NULL,    /* custom CHECKMARK imagery */
  163.     (UBYTE *)"Enter command",    /* window title */
  164.     NULL,    /* custom screen pointer */
  165.     NULL,    /* custom bitmap */
  166.     5,5,    /* minimum width and height */
  167.     -1,-1,    /* maximum width and height */
  168.     WBENCHSCREEN    /* destination screen type */
  169. };
  170.  
  171.  
  172. extern void Warn( const char * );
  173.  
  174. extern struct Window *Win;
  175. extern char CmdWindow[];
  176.  
  177. static struct Window *ReqWin;
  178.  
  179. void Command(void)
  180. {
  181.     struct IntuiMessage *Message;
  182.     ULONG Class;
  183.     USHORT Code;
  184.     struct Gadget *G;
  185.     BPTR fh;
  186.     BOOL End = FALSE;
  187.     char readbuffer[2];
  188.  
  189.     ReqNewWin.BlockPen = Win->BlockPen;
  190.     ReqNewWin.DetailPen = Win->DetailPen;
  191.     if ( (fh = Open( CmdWindow , MODE_NEWFILE )) == NULL ) {
  192.         Warn( "Can't open output window" );
  193.         return;
  194.     }
  195.     if ( (ReqWin = OpenWindow(&ReqNewWin)) == NULL ) {
  196.         Warn( "Can't open Requester" );
  197.         Close( fh );
  198.         return;
  199.     }
  200.     ActivateGadget( &Gadget3 , ReqWin , NULL );
  201.     while( !End ) {
  202.         Wait( 1L << ReqWin->UserPort->mp_SigBit );
  203.         Message = (struct IntuiMessage *)GetMsg(ReqWin->UserPort);
  204.         Class = Message->Class;
  205.         Code = Message->Code;
  206.         G = (struct Gadget *) Message->IAddress;
  207.         ReplyMsg( (struct Message *)Message );
  208.         switch(Class) {
  209.         case GADGETUP :
  210.             CloseWindowSafely( ReqWin , NULL );
  211.             End = TRUE;
  212.             switch( G->GadgetID ) {
  213.             case OK :
  214.             case STRING :
  215.                 Execute( (char *)Buffer , NULL , (struct FileHandle *)fh );
  216.                 Write( fh , "Hit return...›0 p" , 27L );
  217.                 Read( fh , readbuffer , 1L );
  218.                 break;
  219.             case CANCEL :
  220.                 break;
  221.             }
  222.             break;
  223.         case ACTIVEWINDOW :
  224.             ActivateGadget( &Gadget3 , ReqWin , NULL );
  225.             break;
  226.         default :
  227.             ; /* do nothing! */
  228.         }
  229.     }
  230.     Close( fh );
  231. }
  232.